﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Persistence.Dao;
using Domain;
using Common;
namespace web.manage
{
    public partial class Product_ProductType_Operate : adminBase
    {
        int level = DNTRequest.GetInt("level", 0);
        int parentid = DNTRequest.GetInt("parentid", 0);
        int isedit = DNTRequest.GetInt("isedit", 0);
        int id = DNTRequest.GetQueryInt("id", 0);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (isedit == 1)
                {
                    btnAdd.Visible = false;
                    btnEdit.Visible = true;
                    ProductType type = new ProductTypeDao().GetModel(id);
                    if (type != null)
                    {
                        txtName.Text = type.productTypeName;
                        txtOrderId.Text = type.orderId.ToString();
                    }
                }
                else
                {
                    btnAdd.Visible = true;
                    btnEdit.Visible = false;
                }
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ProductType type = new ProductType();
            type.productTypeName = txtName.Text.Trim();
            type.orderId = Utils.StrToInt(txtOrderId.Text, 0);
            type.productTypeLevel = level;
            type.parentID = parentid;
            new ProductTypeDao().Insert(type);
            Message.alert("操作成功");
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {

            ProductType type = new ProductType();
            type.productTypeID = id;
            type.productTypeName = txtName.Text.Trim();
            type.orderId = Utils.StrToInt(txtOrderId.Text, 0);
            type.productTypeLevel = level;
            type.parentID = parentid;
            new ProductTypeDao().Update(type);
            Message.alert("操作成功");
        }

    }
}
